<template>

  <div class="login">
    
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>用户登录</span>
          <el-button style="float: right; padding: 3px 0" type="text"></el-button>
        </div>
        
        <el-form ref="form" :model="users" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="users.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="users.password" show-password></el-input>
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即登录</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>



      </el-card>






    
  </div>
</template>

<script>
  import { createNamespacedHelpers } from 'vuex'
  const { mapActions } = createNamespacedHelpers('Users')

  export default {
    data() {
      return {
        users: {
          username: 'a123123',
          password: '123123',
        }
      }
    },
    methods: {
      ...mapActions(['userLogin']),
      //---------------------------------------用户登录---------------------------------------------
      async onSubmit() {
         const data = await this.userLogin(this.users)
        if(data.code){
          localStorage.token = data.token
          this.$message({
          message: '登录成功',
          type: 'success'
        });
      //---------------------------------------登录成功跳转至home----------------------------------------  
        this.$router.push('/home')
        }
      }
    }
  }
</script>

<style scoped>
.login{
  width: 400px;
  margin: 200px auto;
}
</style>

